<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

<script type="text/javascript">
$(document).ready(function() {
	$('#recordList').datagrid({
		fit: true, 
		nowrap: false,
		striped: true,
		singleSelect: true,
		url: '<c:url value="/system/record/recordList.do"/>',
		//sortName: '',
		//sortOrder: 'desc',
		idField: 'id',
		frozenColumns: [[
			{field:'ck',checkbox:true},
			{field:'id',title:'id',width:150,sortable:true,hidden:true},
			{field:'browsetime',title:'浏览时间',width:120,sortable:true},
		    {field:'computername',title:'计算机',width:150,sortable:true}
		]],
		columns: [[
			{field:'computergroup',title:'计算机组',width:100,sortable:true},
			{field:'controluser',title:'用户',width:100,sortable:true},
			{field:'usergroup',title:'用户组',width:160,sortable:true},
			{field:'domain',title:'网站',width:100,sortable:true},
			{field:'title',title:'标题',width:160,sortable:true},
			{field:'url',title:'网址',width:220,sortable:true},
			{field:'browser',title:'浏览器',width:100,sortable:true}
		]],
		toolbar: [{
			text: '新增',
			iconCls: 'icon-add',
			handler: function(){
				 addRecord(1);
			}
		},
		{
			text: '删除',
			iconCls: 'icon-remove',
			handler: function(){
				delRecord();
			}
		},
		/*{
			text: '修改',
			iconCls: 'icon-edit',
			handler: function(){
				addRecord(2);
			}
		},*/
		{
			text: '查询',
			iconCls: 'icon-search',
			handler: function(){
				searchRecord();
			}
		},'-',{
			text: '导入',
			iconCls: 'icon-save',
			handler: function(){
				inputRecord();
			}
		}], 
		pageSize: 20,
		pagination: true,
		rownumbers: true,
		onClickRow:function(rowIndex, rowData) {
			$('#recordList').datagrid('clearSelections').datagrid('selectRow',rowIndex);	
		}
	});
}); 



//查询任务
function searchRecord(){
	$('#dlgQueryRecord').dialog({
		title: '查询条件设置',
		modal: true,
		closable: true,
		draggable: true,
		width: 380,
		height: 160,
		toolbar: [{
			text:'查询',
			iconCls:'icon-search',
			handler:function(){
				queryRecord();
			}
		},{
			text:'关闭',
			iconCls:'icon-cancel',
			handler: function() {
				$('#dlgQueryRecord').dialog('close');
			}
		}],
		onBeforeOpen: function() {
			$('#frmQueryRecord')[0].reset();
		}
	}).dialog('open');
}

//根据条件查询
function queryRecord(){
	var computername = $('#frmQueryRecord #computername').val();
	var qtime =  $("#qtime").datebox("getValue"); 
	var queryParams = $('#recordList').datagrid('options').queryParams;
	queryParams.computername= computername;
	queryParams.qtime = qtime; 
	$('#recordList').datagrid('options').url = '<c:url value="/system/record/recordList.do"/>';
	$('#recordList').datagrid('options').queryParams = queryParams;
	$("#recordList").datagrid('load');
	$('#dlgQueryRecord').dialog('close');
}

function addRecord(flag){
	var url = '<c:url value="/system/record/recordAdd.do"/>'; 
	var title;
	if(flag==1){
		title = '上网记录添加'; 
	}else{
		title = '上网记录修改';
		var recodeRow = $('#recordList').datagrid('getSelected');
		if(recodeRow == null){
			$.messager.alert('提示', '请选择您要修改的数据！', 'info'); 
			return;
		}
		var r_id = recodeRow.id;
		url = url +'?id='+r_id;
	}
	$('#dlgAddRecord').dialog('close').remove();
	$('body').append('<div id="dlgAddRecord" class="easyui-dialog" closed="true"></div>');
	$('#dlgAddRecord').dialog({
		title:title,
		modal:true,
		singleSelect:true,
		closable:true,
		draggable:false,
		width:630,
		height:240,
		toolbar:[{
			text:'保存',
			iconCls:'icon-save',
			handler:function(){
				saveRecord();
			}
		},{
			text:'关闭',
			iconCls:'icon-cancel',
			handler:function(){
				$('#dlgAddRecord').dialog('close');
			}
		}]
	}).dialog('open').dialog('refresh',url);
}



function delRecord(){
	var row = $('#recordList').datagrid('getSelected');
	if(row == null){
		$.messager.alert('错误', '请选择您要删除的数据！', 'error'); 
		return;
	}
	else {
		$.messager.confirm('警告', '您确认删除么?', function(r){
			if(r){
				$.ajax({
					url: '<c:url value="/system/record/delRecord.do"/>',
					type: 'POST',
					data: 'id='+row.id,
					beforeSend: function(XmlHttpRequest, textStatus, errorThrown) {
						$.messager.progress({
							title:'提示',
							msg:'正在执行数据操作，请稍待...'
						});
					},
					success: function(result) {
						$.messager.progress('close');
						if(!result.success) {
							$.messager.alert('错误', result.data , 'error');
						}
						else {
							$.messager.alert('提示', result.data , 'info');		
							$('#recordList').datagrid('clearSelections').datagrid('reload');
						}
					}
				});
			}
		});
	}
}

function inputRecord(){
	$('#dlgRecordFile').dialog({
		title: '导入上网记录',
		modal: true,
		closable: true,
		draggable: true,
		width: 390,
		height: 120,
		toolbar: [{
			text:'保存',
			iconCls:'icon-save',
			handler: function() {
				saveRecords();
			}
		},{
			text:'关闭',
			iconCls:'icon-cancel',
			handler: function() {
				$('#dlgRecordFile').dialog('close');
			}
		}] 
	}).dialog('open');
}

function saveRecords(){
	var filepath = document.getElementById("records");
	$('#msg').show();
	if (filepath!=null){
		$.ajaxFileUpload({
			url: '<c:url value="/system/record/saveRecords.do"/>',
			secureuri:false,
			fileElementId:'records',
			dataType: 'json', 
			success: function (result){
				$('#dlgRecordFile').dialog('close').remove();
				if(result.success){
					$('#recordList').datagrid('reload');
					$('#msg').hide();
					$.messager.alert('提示', result.data , 'info');		
				}else{
					$.messager.alert('错误', result.data , 'info');
				}
			}
		});
	}
} 


</script>


<table id="recordList" > </table> 
<div id="dlgRecordFile" class="easyui-dialog" style="padding: 5px;overflow: hidden;" closed="true">
	<div id="recordFile" style="float:left;margin:1px 1px 0 0;"> 
	导入上网记录文件：<input id="records" type="file" name="records"  style="width:240px;"/>
	</div>
	<div id="msg" style="text-align:center;display:none;"><font color=red>正在导入,请稍侯...</font>
	</div>
</div>


<div id="dlgQueryRecord" class="easyui-dialog" style="padding: 5px;overflow: hidden;" closed="true">
		<form name="frmQueryRecord" id="frmQueryRecord">
			<table width="100%" border="0" class="formTableShadow" cellpadding="1" cellspacing="1">
				<tr>
					<th>计算机：</th>
					<td>
						<input type="text" id="computername" name="computername" class="easyui-validatebox" style="width:200px;" />
					</td>
				</tr> 
				<tr>
					<th>浏览时间：</th>
					<td>
						<input type="text" id="qtime" name="qtime" class="easyui-datebox" style="width:200px;"  readonly="readonly"/>
					</td>
				</tr>
			</table>
		</form>
	</div>
 